var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();

Page({
  data: {
     // 默认选中菜单
     currentTab: 0,
     index: 0,
     orderNo: '',
    categoryFilter: false,
    clientOrderConfirm: [],
    categoryId: 0
  },
  getData: function () {
    let that = this;
    that.getClientOrderConfirm();
  },
  getClientOrderConfirm() {
    var that = this;
    console.log('获取订单详情')
    util.request(api.ClientOrderConfirm, {orderNo: that.data.orderNo })
      .then(function (res) {
        if (res.errno === 0) {
          that.setData({
            clientOrderConfirm: res.data
          });
        }
      });
  },
  goConfirm: function (e) {
   //确认
   let that = this;
   var orderNo = e.target.dataset.orderNo;
   console.log("orderNo:"+orderNo);
   wx.showModal({
    title: '提示',
    content: '通过此订单?',
    success: function (res) {
      if (res.confirm) {
        
        util.request(api.ClientOrderGoConfirm, { orderNo: orderNo }).then(function (res) {
          if (res.errno === 0) {
            wx.showToast({
              title: '确认完成',
              icon: 'success',
              duration: 2000
            });
            that.getClientOrderConfirm();
          }
        });
        
        console.log('用户已确认订单');
      } else if (res.cancel) {
        console.log('用户点击取消');
      }
    }
  })



  },
  goCancel: function (e) {
   //取消
   let that = this;
   var orderNo = e.target.dataset.orderNo;
   console.log("orderNo:"+orderNo);
   wx.showModal({
    title: '提示',
    content: '取消此订单?',
    success: function (res) {
      if (res.confirm) {
        
        util.request(api.ClientOrderGoCancel, { orderNo: orderNo }).then(function (res) {
          if (res.errno === 0) {
            wx.showToast({
              title: '已取消',
              icon: 'success',
              duration: 2000
            });
            that.getClientOrderConfirm();
          }
        });

        console.log('用户已取消订单');
      } else if (res.cancel) {
        console.log('用户点击取消');
      }
    }
  })
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this
    that.setData({
      orderNo: options.orderNo
    })
    that.getData();
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  }
})